package com.tarena.lbs.user.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.user.dao.mapper.UserMapper;
import com.tarena.lbs.user.dao.repository.UserRepository;
import com.tarena.lbs.user.pojo.po.UserPO;
import lombok.extern.slf4j.Slf4j;
import com.tarena.lbs.user.pojo.vo.TagListVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Slf4j
public class UserRepositoryImpl implements UserRepository {

    private static final Logger log = LoggerFactory.getLogger(UserRepositoryImpl.class);
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserPO getByPhone(String phone) {
        QueryWrapper<UserPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone",phone);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public Long countUserByPhone(String phone) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("phone",phone);
        return userMapper.selectCount(queryWrapper);
    }

    @Override
    public void save(UserPO poParam) {
        userMapper.insert(poParam);
    }

    @Override
    public UserPO getById(Integer userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public void update(UserPO poToUpdate) {
        int po =userMapper.updateById(poToUpdate);
        log.debug("更新用户数据成功,更新数据:{}条",po);
    }

    @Override
    public List<TagListVO> bindUserTags(Integer id) {
        List<TagListVO> tagList = userMapper.bindUserTags(id);
        log.debug("用户标签关联结果：{}",tagList);
        return tagList;
    }

    @Override
    public List<Map<String, Object>> getRegisterCount() {
        return userMapper.getRegisterCount();
    }
}
